/*
 * TPL0202.c
 *
 * Created: 02.04.2012 22:42:01
 *  Author: Administrator
 */ 

#include <avr/io.h>
#include <avr/delay.h>
#include "TPL0202.h"

void init_DPoti(void)
{
	DPotiCSPort |= (1 << DPotiCS);
	DDRB |= (1<<DPotiCS) | (1<<PINB7) | (1<<PINB5);		// CS, SCK, MOSI
	DDRB &= ~(1<<PINB6);				// MISO	
	DPotiCSPort |= (1 << DPotiCS);
	SPCR0 |= (1<<SPE0) | (1<<MSTR0) | (1<<SPR00) | (1<<SPR10);
	_delay_ms(10);
}

void setDPoti(uint8_t command, uint8_t data)
{
	DPotiCSPort &= ~(1 << DPotiCS);
	SPDR0 = command;
	while(! ( SPSR0 & (1<<SPIF0) ) );
	SPDR0 = data;
	while(! ( SPSR0 & (1<<SPIF0) ) );
	DPotiCSPort |= (1 << DPotiCS);
}